<ul class="jstree-children">
	<ng-container *ngFor="let item of data; let last = last">
		<li
			class="jstree-node"
			[class.jstree-last]="last"
			[class.jstree-open]="item.children.length"
			[class.jstree-leaf]="!item.children.length"
			[class.jstree-closed]="childrenRef.closed"
		>
			<i class="jstree-icon jstree-ocl" (click)="childrenRef.closed = !childrenRef.closed"></i>
			<ng-container *ngIf="selection">
				<ng-container *ngIf="selection.multiple; else simpleRef">
					<mat-checkbox [checked]="selection.isSelected(item)" (change)="select(item)"> </mat-checkbox>
				</ng-container>
				<ng-template #simpleRef>
					<mat-radio-button
						[checked]="selection.isSelected(item)"
						(change)="selection.select(item)"
					></mat-radio-button>
				</ng-template>
			</ng-container>

			<div class="jstree-anchor">
				<ng-container *ngTemplateOutlet="template; context: { $implicit: item }"></ng-container>
			</div>
			<m-tree
				[data]="item.children"
				[level]="level + 1"
				[template]="template"
				[selection]="selection"
				#childrenRef
			>
			</m-tree>
		</li>
	</ng-container>
</ul>
